﻿using NaverOpenApiLibrary.Models;
using System.Collections.Generic;


namespace NaverOpenApiLibrary.Services
{
    /// <summary>
    /// Service that shorten long uri
    /// for more info: see http://dev.naver.com/openapi/apis/function/shorturl
    /// </summary>
    public class UrlShortnerService : NaverApiService<UrlInfo>
    {
        // Uri pattern : "http://openapi.naver.com/shorturl.json?url={0}&key={1}";
        protected const string URL_SHORTEN_SERVICE_API = "http://openapi.naver.com/shorturl.json";
        private string _urlToShorten;

        public UrlShortnerService(string apiKey)
            : base(apiKey, URL_SHORTEN_SERVICE_API)
        {
            // Do Nothing...
        }

        public void DoShorten(string urlToShorten) {
            this._urlToShorten = urlToShorten;
            base.DoApiService();
        }

        protected override IDictionary<string, string> GetApiUriParameters()
        {
            return new Dictionary<string, string>() {
                {"url", this._urlToShorten}
            };
        }

        protected override UrlInfo Deserialize(string rawResultData)
        {
            return base.ParseJsonResult(rawResultData);
        }

    }
}
